package com.binguo.api.controller;

import com.binguo.api.result.Result;
import com.binguo.api.result.ResultGenerator;
import com.binguo.model.model.Advert;
import com.binguo.model.repository.AdvertRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;

import java.util.List;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

/**
 * @author yuritian
 * @Title: AdvertController
 * @ProjectName binguoDevelop
 * @Description: TODO
 * @date 2019-11-3014:51
 */
@Api(tags = "广告")
@RestController
@RequestMapping
public class AdvertController {

    @Autowired
    AdvertRepository advertRepository;

    @GetMapping(value = "/api/advert/list/{shopId}", produces = APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取广告列表")
    public Result getOrders(@PathVariable Integer shopId){

        Condition condition = new Condition(Advert.class);
        condition.or().andEqualTo("shopId",shopId)
                .andEqualTo("advertOwner",1)
                .andEqualTo("location",1);
        List<Advert> advertList = advertRepository.findByCondition(condition);

        return ResultGenerator.genSuccessResult(advertList);
    }
}
